package com.stylefeng.guns.rest.modular.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @ClassName ResponseVO
 * Created by zghgchao 2019/8/2 22:54
 **/
@Data
@NoArgsConstructor
@AllArgsConstructor
//@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResponseVO<M> {

    // 返回状态【0-成功，1-失败，999-系统异常】
    private int status;
    // 返回信息
    private String msg;
    // 返回数据实体
    private M data;

    // 图片前缀
    private String imgPre;

    // 分页使用
    private int nowPage;
    private int totalPage;

    public static<M> ResponseVO success(M m){
        ResponseVO<Object> responseVO = new ResponseVO<>();
        responseVO.setStatus(0);
        responseVO.setData(m);
        return responseVO;
    }

    public static<M> ResponseVO success(String imgPre,M m){
        ResponseVO<Object> responseVO = new ResponseVO<>();
        responseVO.setStatus(0);
        responseVO.setData(m);
        responseVO.setImgPre(imgPre);
        return responseVO;
    }

    public static<M> ResponseVO success(int nowPage,int totalPage,String imgPre,M m){
        ResponseVO<Object> responseVO = new ResponseVO<>();
        responseVO.setStatus(0);
        responseVO.setData(m);
        responseVO.setImgPre(imgPre);
        responseVO.setNowPage(nowPage);
        responseVO.setTotalPage(totalPage);
        return responseVO;
    }

    public static<M> ResponseVO success(String msg){
        ResponseVO<Object> responseVO = new ResponseVO<>();
        responseVO.setStatus(0);
        responseVO.setMsg(msg);
        return responseVO;
    }


    /**
     * 业务异常
     * @param msg
     * @return
     */
    public static ResponseVO serviceFail(String msg){
        ResponseVO<Object> responseVO = new ResponseVO<>();
        responseVO.setStatus(1);
        responseVO.setMsg(msg);
        return responseVO;
    }

    /**
     * 系统异常
     * @param msg
     * @return
     */
    public static ResponseVO appFail(String msg){
        ResponseVO<Object> responseVO = new ResponseVO<>();
        responseVO.setStatus(999);
        responseVO.setMsg(msg);
        return responseVO;
    }
}
